{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>工具管理员</legend>
    </fieldset>
    <blockquote class="layui-elem-quote">
        <a href="{:url('adminAddUI')}" class="layui-btn layui-btn-sm">添加工具管理员</a>
    </blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>

{include file="common/foot"/}
<script type="text/html" id="barDemo">

    <a href="{:url('accessUI')}?id={{d.admin_id}}" class="layui-btn layui-btn-xs layui-btn-normal">分配权限</a>
    <a href="{:url('adminEditUI')}?admin_id={{d.admin_id}}" class="layui-btn layui-btn-xs">{:lang('edit')}</a>

    {{# if(gid==1){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
    {{# } }}
</script>
<script type="text/html" id="open">
    {{# if(d.admin_id==1){ }}
    <input type="checkbox" disabled name="is_open" value="{{d.admin_id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" checked>
    {{# }else{  }}
    <input type="checkbox" name="is_open" value="{{d.admin_id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="open" {{ d.is_open == 1 ? 'checked' : '' }}>
    {{# } }}
</script>
<script>

    var gid = '{:session("gid")}';
    var wh = {gid:8};
    if(gid=='1'){
        han();
    }else if(gid=='8'){
        wh.apid = '{:session("aid")}';
        wh.is_part = 1;
        han();
    }else{
        han()
    }

    function han() {
        layui.use(['table','form'], function() {
            var table = layui.table,form = layui.form,$ = layui.jquery;
            var cols = [[
                {field:'email', title: '邮箱', width:200}
                ,{field:'title', title: '{:lang("userGroup")}', width:200}
                ,{field:'tel', title: '{:lang("tel")}', width:150}
                ,{field:'ip', title: '{:lang("ip")}',width:150}
                ,{field:'is_open', title: '{:lang("status")}',width:150,toolbar: '#open'}
                ,{width:180, align:'center', toolbar: '#barDemo'}
            ]];
            if(gid == '1'){
                cols[0].unshift({field:'as_name', title: '所属单位', width:150});
            }
            cols[0].unshift({field:'name', title: '名称', width:150});
            cols[0].unshift({field:'username', title: '用户名', width:80,fixed: true});

            var tableIn = table.render({
                elem: '#list',
                url: '{:url("queryAdmin")}',
                method:'post',
                cols: cols
                ,where:wh
            });
            form.on('switch(open)', function(obj){
                loading =layer.load(1, {shade: [0.1,'#fff']});
                var id = this.value;
                var is_open = obj.elem.checked===true?1:0;

                $.post('{:url("adminState")}',{'id':id,'is_open':is_open},function (res) {
                    layer.close(loading);
                    if (res.status==1) {

                        //tableIn.reload();

                        layer.msg('操作成功',{icon:6});

                    }else{
                        layer.msg(res.msg,{time:1000,icon:2});
                        return false;
                    }
                })
            });
            table.on('tool(list)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    layer.confirm('{:lang("Are you sure you want to delete it")}', function(index){
                        $.post("{:url('Auth/adminDel')}",{admin_id:data.admin_id},function(res){
                            if(res.code==1){
                                layer.msg(res.msg,{time:1000,icon:1});
                                obj.del();
                            }else{
                                layer.msg(res.msg,{time:1000,icon:2});
                            }
                        });
                        layer.close(index);
                    });
                }
            });

        });
    }
</script>
</body>
</html>